class StatusEnum {
	static get SUCCESS() {
		return 200;
	}
	static get SUCCESS_NAME() {
		return "SUCCESS";
	}
	static get WARNING() {
		return 300;
	}
	static get WARNING_NAME() {
		return "WARNING";
	}
	static get ERROR() {
		return 400;
	}
	static get ERROR_NAME() {
		return "ERROR";
	}
	static get EXCEPTION() {
		return 500;
	}
	static get EXCEPTION_NAME() {
		return "EXCEPTION";
	}
	static get BOOLEAN() {
		return "boolean"
	}
	static get NUMBER() {
		return "number"
	}
	static get STRING() {
		return "string"
	}
	static get FUNCTION() {
		return "function"
	}
	static get ARRAY() {
		return "array"
	}
	static get DATE() {
		return "date"
	}
	static get REGEXP() {
		return "regExp"
	}
	static get UNDEFINED() {
		return "undefined"
	}
	static get NULL() {
		return "null"
	}
	static get OBJECT() {
		return "object"
	}
	static get DAY() {
		return "day"
	}
	static get MONTH() {
		return "month"
	}
	static get WEEK() {
		return "week"
	}
}
//字典对象
class DictItem {
	constructor({
		type = "",
		data = [],
		name = "",
		subjectCode = "",
		subjectName = ""
	} = {}) {
		this.type = type;
		this.data = data;
		this.name = name;
		this.subjectCode = subjectCode;
		this.subjectName = subjectName;
	}
}

class Common {
	constructor({
		typeCode = "",
		typeName = ""
	} = {}) {
		this.typeCode = typeCode;
		this.typeName = typeName;
	}

}

class Result extends Common {
	constructor({
		data = "",
		errorMessage = "",
		hasErrors = false,
		success = false,
		exceptionData = "",
		inputData = "",
		typeCode = "",
		typeName = ""
	} = {}) {
		// 优先调用父类构造函数
		super({
			typeCode,
			typeName
		});
		this.data = data;
		this.errorMessage = errorMessage;
		this.success = success;
		this.exceptionData = exceptionData;
		this.inputData = inputData;
		this.hasErrors = hasErrors;
	}

}
class Logger {

	constructor({
		message = "",
		date = "",
		action = "",
		exceptionData = "",
		info = "",
		inputData = ""
	} = {}) {
		this.message = message;
		this.date = date;
		this.action = action;
		this.info = info;
		this.exceptionData = exceptionData;
		this.inputData = inputData;
	}
}



class TimingLogger extends Common {
	constructor({
		occur_dt = "",
		occur_date = "",
		occur_year_month = "",
		occur_year = "",
		typeCode = "",
		typeName = "",
		info = "",
		action = "",
		exceptionData = "",
	} = {}) {
		super({
			typeCode,
			typeName
		});
		this.occur_dt = occur_dt;
		this.occur_date = occur_date;
		this.occur_year_month = occur_year_month;
		this.occur_year = occur_year;
		this.info = info;
		this.action = action;
		this.exceptionData = exceptionData;
	}
}

class Clock {
	constructor() {}

	now(pattern = "YYYY-MM-DD hh:mm:ss", nowDT = new Date(), timeZone = 8, types = ["YYYY", "MM", "DD", "hh", "mm",
		"ss"
	]) {
		// 默认东八区
		const curNowDT = this.getLocalTime(timeZone, nowDT);
		return types.reduce((pre, cur) => {
			return pre.replace(cur, this.captureDateTime(cur, curNowDT))
		}, pattern)
	}
	static now(pattern = "YYYY-MM-DD hh:mm:ss", nowDT = new Date(), timeZone = 8, types = ["YYYY", "MM", "DD", "hh",
		"mm",
		"ss"
	]) {
		// 默认东八区
		const curNowDT = this.getLocalTime(timeZone, nowDT);
		return types.reduce((pre, cur) => {
			return pre.replace(cur, this.captureDateTime(cur, curNowDT))
		}, pattern)
	}
	static getLocalTime(i = 8, d = new Date()) {
		//参数i为时区值数字，比如北京为东八区则输入+8,西5输入-5
		//参数d为要转换的时间(Date类型)
		var len = d.getTime();
		//本地时间与GMT时间的时间偏移差
		var offset = d.getTimezoneOffset() * 60000;
		//得到现在的格林尼治时间
		var utcTime = len + offset;
		return new Date(utcTime + 3600000 * i);
	}
	getLocalTime(i, d) {
		//参数i为时区值数字，比如北京为东八区则输入+8,西5输入-5
		//参数d为要转换的时间(Date类型)
		var len = d.getTime();
		//本地时间与GMT时间的时间偏移差
		var offset = d.getTimezoneOffset() * 60000;
		//得到现在的格林尼治时间
		var utcTime = len + offset;
		return new Date(utcTime + 3600000 * i);
	}


	captureDateTime(tar, date) {
		const dtMap = new Map([
			["YYYY", date.getFullYear()],
			["MM", this.trim(date.getMonth())],
			["DD", this.trim(date.getDate())],
			["hh", this.trim(date.getHours())],
			["mm", this.trim(date.getMinutes())],
			["ss", this.trim(date.getSeconds())]
		])
		return dtMap.get(tar);
	}
	static captureDateTime(tar, date) {
		const dtMap = new Map([
			["YYYY", date.getFullYear()],
			["MM", this.trim(date.getMonth())],
			["DD", this.trim(date.getDate())],
			["hh", this.trim(date.getHours())],
			["mm", this.trim(date.getMinutes())],
			["ss", this.trim(date.getSeconds())]
		])
		return dtMap.get(tar);
	}
	trim(sour) {
		return sour < 10 ? `0${sour}` : sour
	}
	static trim(sour) {
		return sour < 10 ? `0${sour}` : sour
	}
}
module.exports = {
	Result,
	Logger,
	TimingLogger,
	Clock,
	StatusEnum,
	DictItem
}
